<template>
  <div class="editor" @click="showDrawer" :style="view?'border: none':(props.rich?'border: 1px dashed transparent;cursor: pointer;':'border: 1px dashed #292d33;cursor: pointer;')">
    <div class="content" v-html="props.rich" v-if="props.rich"></div>
    <div class="noContent acea-row row-middle row-column row-center" v-if="props.rich == '' && !view">
      <a-icon type="plus" />
      <div>添加内容</div>
    </div>
    <drawer :attr="list.attr" :show.sync="show" @change="editAttr" :index="list.index" />
  </div>
</template>

<script>
import drawer from "../drawer"
import changeAttr from '@/utils/changeAttr.js'
import changeViewAttr from '@/utils/changeViewAttr.js'

export default {
  components:{
    drawer
  },
  name:"tmpEditor",
  props:{
    list:{
      type:Object,
    },
    view:{
      type:Boolean,
      default:false
    }
  },
  data() {
    return {
      show:false,
      props:{},
      changeAttr,
    }
  },
  created() {
    this.editAttr()
  },
  methods: {
    showDrawer(){
      if(!this.view){
        this.show = true
      }
    },
    editAttr(){
      if(this.view){
        this.props = changeViewAttr(this.list.attr,this.list.index)
      }else{
        this.props = changeAttr(this.list.attr,this.list.index)
      }
    }
  },
}
</script>

<style scoped>
  .editor{
    box-sizing: border-box;
    border: 1px dashed transparent;
  }
  .editor:hover{
    border: 1px dashed #1989fa !important;
  }
  .editor .noContent{
    height: 100px;
    padding: 20px 0;
  }
  .tmp-checkbox{
    padding-bottom: 0;
  }
  .checkbox .van-checkbox--horizontal{
    margin-bottom: 10px;
  }
  .content >>> img{
    width: 100%;
  }
</style>